load("@fbcode_macros//build_defs/lib:rust_oss.bzl", "rust_oss")
load("@fbsource//tools/build_defs:rust_binary.bzl", "rust_binary")
load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library")

oncall("sapling")

rust_library(
    name = "configloader",
    srcs = glob(["src/**/*.rs"]),
    autocargo = {
        "cargo_target_config": {"crate_type": [
            "staticlib",
            "lib",
        ]},
        "cargo_toml_config": {
            "bench": [{
                "harness": False,
                "name": "bench",
            }],
            "dependencies_override": {"dependencies": {"sapling-version": {"path": "../../version"}}},
            "extra_buck_dependencies": {"dev-dependencies": ["//eden/scm/lib/minibench:minibench"]},
            "features": {
                "default": [],
                "fb": [
                    "sapling-types",
                    "sapling-identity/fb",
                    "sapling-config-remote-loader/fb",
                    "filetime",
                    "sapling-hgtime",
                    "sapling-http-client",
                    "regex",
                    "serde_json",
                    "serde",
                    "serde_urlencoded",
                ],
                "sl_oss": [],
            },
            "lib": {"name": "configloader"},
            "package": {
                "authors": ["Meta Source Control Team <sourcecontrol-dev@meta.com>"],
                "homepage": "https://sapling-scm.com/",
                "license": "MIT",
                "name": "sapling-configloader",
                "repository": "https://github.com/facebook/sapling",
            },
        },
    },
    crate_root = "src/lib.rs",
    features = [
        "fb",
    ],
    os_deps = [
        (
            "linux",
            ["//infrasec/authorization/if:if-aclchecker-rust-srclients"],
        ),
    ],
    test_deps = [
        "fbsource//third-party/rust:once_cell",
        "fbsource//third-party/rust:tempfile",
        "//eden/scm/lib/util/testutil:testutil",
    ] + ([] if rust_oss.is_oss_build() else [
        "fbsource//third-party/rust:tempfile",
    ]),
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:tracing",
        "//eden/scm/lib/config/model:configmodel",
        "//eden/scm/lib/config/set:configset",
        "//eden/scm/lib/config/static:staticconfig",
        "//eden/scm/lib/config/union:unionconfig",
        "//eden/scm/lib/gitcompat:gitcompat",
        "//eden/scm/lib/identity:identity",
        "//eden/scm/lib/minibytes:minibytes",
        "//eden/scm/lib/repo/repo-minimal-info:repo-minimal-info",
        "//eden/scm/lib/repo/url:repourl",
        "//eden/scm/lib/util/hgplain:hgplain",
    ] + ([] if rust_oss.is_oss_build() else [
        "//devx_www/cross_env_session_id:cross_env_session_id",
        "fbsource//third-party/rust:dirs",
        "fbsource//third-party/rust:faccess",
        "fbsource//third-party/rust:filetime",
        "fbsource//third-party/rust:hostname",
        "fbsource//third-party/rust:parking_lot",
        "fbsource//third-party/rust:regex",
        "fbsource//third-party/rust:serde",
        "fbsource//third-party/rust:serde_json",
        "fbsource//third-party/rust:serde_urlencoded",
        "fbsource//third-party/rust:url",
        "//common/rust/fbwhoami:fbwhoami",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/hostcaps:hostcaps",
        "//configerator/structs/infrasec/if:acl-rust",
        "//eden/scm/lib/async-runtime:async-runtime",
        "//eden/scm/lib/config/remote-loader:remote-loader",
        "//eden/scm/lib/hgtime:hgtime",
        "//eden/scm/lib/http-client:http-client",
        "//eden/scm/lib/spawn-ext:spawn-ext",
        "//eden/scm/lib/thrift-types:thrift-types",
        "//eden/scm/lib/types:types",
        "//eden/scm/lib/util:util",
        "//eden/scm/lib/version:rust_version",
        "//infrasec/authorization/if:if-aclchecker-rust-clients",
        "//infrasec/authorization/if:if-aclchecker-rust-x2pclients",
    ]),
)

rust_binary(
    name = "bench",
    srcs = ["benches/bench.rs"],
    autocargo = {"ignore_rule": True},
    deps = [
        "fbsource//third-party/rust:tempfile",
        "//eden/scm/lib/config/loader:configloader",
        "//eden/scm/lib/minibench:minibench",
        "//eden/scm/lib/repo/repo-minimal-info:repo-minimal-info",
    ],
)
